<template>
    <view>
        <view class="item">
            <view>用户名</view>
            <view><input type="text" placeholder="请输入用户名" v-model="username"></view>
        </view>

        <view class="item">
            <view>密码</view>
            <view><input type="password" placeholder="请输入密码" v-model="pass_show"></view>
        </view>
        <view class="item">
            <view>联系方式</view>
            <view><input type="text" placeholder="请输入联系方式" v-model="mobile"></view>
        </view>
        <view class="item">
            <view>微信账号</view>
            <view><input type="text" placeholder="请输入微信账号" v-model="wechat"></view>
        </view>
        <view class="item">
            <view>备注信息</view>
            <view><input type="text" placeholder="备注信息" v-model="content"></view>
        </view>
        <!-- <view class="items">
            <view>会员类型</view>
            <view @click="show = true">{{ typeName }}</view>
        </view> -->
        <view class="submit" @click="submit">确认</view>
        <!-- <u-picker :show="show" :columns="columns" keyName="name" @confirm="confirmType" @cancel="closeType"></u-picker> -->
    </view>
</template>

<script>
import { useradd } from "@/api/user.js"
export default {
    components: {},
    props: {},
    data() {
        return {
            type: '3',
            // typeName: '请选择会员类型',
            username: '',
            pass_show: '',
            show: false,
            passShow: true,
            id: '',
            mobile: '',
            content: '',
            wechat: '',
            // columns: [
            //     [{
            //         name: '运输车车主',
            //         id: 2,
            //     }, {
            //         name: '车队队长',
            //         id: 3,
            //     }]
            // ],
        };
    },
    watch: {},
    methods: {
        confirmType(e) {
            console.log(e)
            this.typeName = e.value[0].name
            this.type = e.value[0].id
            this.show = false;
        },
        closeType() {
            this.typeName = '请选择会员类型'
            this.type = ''
            this.show = false;
        },
        submit() {
            if (this.username == '') {
                uni.showToast({
                    title: '请输入用户名',
                    icon: 'none',
                    mask: true
                })
                return false;
            }
            if (this.pass_show == '') {
                uni.showToast({
                    title: '请输入密码',
                    icon: 'none',
                    mask: true
                })
                return false;
            }
            if (this.mobile == '') {
                uni.showToast({
                    title: '请输入联系方式',
                    icon: 'none',
                    mask: true
                })
                return false;
            }
            if (this.wechat == '') {
                uni.showToast({
                    title: '请输入微信账号',
                    icon: 'none',
                    mask: true
                })
                return false;
            }
            useradd({
                username: this.username,
                pass_show: this.pass_show,
                type: this.type,
                mobile: this.mobile,
                id: this.id,
                wechat: this.wechat,
                content: this.content,

            }).then(res => {
                console.log(res)
                if (res.code == 1) {
                    uni.showToast({
                        title: '成功～',
                        icon: 'none',
                        mask: true
                    })
                    setTimeout(() => {
                        uni.navigateBack({ delta: 1 })
                    }, 2000)
                }
            })
        }
    },
    onShow() { },
    onLoad(option) {
        if (option.type == 'edit') {
            uni.setNavigationBarTitle({
                title: '编辑车队'
            });
            this.username = option.username;
            this.pass_show = option.pass_show;
            this.id = option.id
            this.mobile = option.mobile
        }
        console.log(option)
    },
};
</script>
<style scoped lang='scss'>
.item {
    width: 94%;
    height: 90rpx;
    border-bottom: 1px solid #efefef;
    margin: auto;
    display: flex;
    line-height: 90rpx;

    view:nth-child(1) {
        width: 30%;
        font-size: 28rpx;
        font-weight: 600;
    }

    view:nth-child(2) {
        width: 70%;

        input {
            font-size: 28rpx;
            width: 100%;
            height: 100%;
            text-align: right;
        }

    }
}

.items {
    width: 94%;
    height: 90rpx;
    border-bottom: 1px solid #efefef;
    margin: auto;
    display: flex;
    line-height: 90rpx;

    view:nth-child(1) {
        width: 30%;
        font-size: 28rpx;
        font-weight: 600;
    }

    view:nth-child(2) {
        width: 70%;
        text-align: right;
        font-size: 28rpx;
        color: $uni-color-primary;
    }
}

.submit {
    width: 94%;
    height: 90rpx;
    background-color: $uni-color-primary;
    border-radius: 50rpx;
    margin: auto;
    margin-top: 130rpx;
    text-align: center;
    line-height: 90rpx;
    color: #fff;
}
</style>